Setup GoLambda

We will setup Golambda in docker container. This way it will help in test in local and pp.

Pre-requisite

  • Install docker
  • Install docker-compose
  • Setup AWS cli

Install Docker 3

Install docker-compose

Setup AWS CLI

Configure AWS CLI

  • run aws configure
  • Access key ID: <>
  • Secret access key: <>
  • After configuration run $(aws ecr get-login --no-include-email --region ap-south-1)

Please refer golambda_vertical (https://github.com/goibibo/golambda_vertical#configure-aws-cli) readme file for credentials.

Start Development - New Vertical and New Intent

  • Clone the repo https://github.com/goibibo/golambda_vertical.git in a new location in working directory.
  • Your golambda project structure should be as below:
  • run docker-compose build and then docker-compose up (if you already have a docker running in another application, restart your docker service before you run these commands)
  • To initialise app: run docker-compose exec golambda_vertical python generator.py init in a new tab.
  • To add a new Action: run docker-compose exec golambda_vertical python generator.py addAction
    • Domain = goibibo , Vertical = train
  • Copy from above repo docker-compose.yml and Dockerfile-Dev in to the root directory of your Lambda project.

Steps to migrate from Diana lambda to Golambda 2.0

After completing above steps mentioned in Start Development - New Vertical and New Intent please follow below steps

  • Create directories <domain>/<vertical> like goibibo/train
  • Copy all your vertical related py files to <domain>/<vertical>
  • Copy contents of your config.py to config.py in root folder.
  • Create constants.py file in root folder.
  • In config.py of the root folder, append your folder path in OWNER_LIST, for eg. goibibo flights team will write OWNER_LIST = ["goibibo.flight"]
  • In config.py file add your docker url like LAMBDA_URL = 'http://gia-train.goibibo.com' if settings.ENV_TYPE == 'prod' else 'http://0.0.0.0:8001'
  • Copy your message files to message_yaml
  • Wherever there are references to constants and confing in your code, change import statment as from vertical.constants import DB_BOOKING_STATUS
  • Replace golambda.goibibo to vertical.goibibo and golambda.makemytrip to vertical.makemytrip in all your py files.

Test your Setup

http

POST /api/action_handler/ HTTP/1.1
Host: localhost:8001
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=

{
        "subIntent": "default",
        "intent": "<Your intent>",
        "context": {
                            "email": "<any valid email>",
                    "mobile": "<any valid phone number>"
                    }
    }

curl

curl -i -X POST http://localhost:8001/api/action_handler/ -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"context": {"email": "<any valid email>", "mobile": "<any valid phone number>"}, "intent": "<Your intent>", "subIntent": "default"}' --user admin:admin

How to update local setup

  • In order to update the golambda image in your local setup, run docker pull 017357459259.dkr.ecr.ap-south-1.amazonaws.com/gia-dev:golambdalatest
  • If you face the authentication issue, run $(aws ecr get-login --no-include-email --region ap-south-1) before running the above command.

Migration to Golambda 3.0

  • In order to migrate to Golambda 3.0, you need to replace line in your docker file from docker pull 017357459259.dkr.ecr.ap-south-1.amazonaws.com/gia-dev:golambdalatest to docker pull 017357459259.dkr.ecr.ap-south-1.amazonaws.com/gia-dev:golambdalatest3.21
  • Run docker-compose build after that